package ranab.unit;

/**
 * Energy unit converter class.
 * 
 * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
 */
public 
class EnergyUnit extends BaseUnit {
    
    private final static String[] UNITS = {
        "joule (J)", 
        "electronvolt (eV)",    
        "erg",   
        "ft.lbf", 
        "calorie (cal)", 
        "kgf.m", 
        "British Thermal Unit (Btu)", 
        "watt hour (W.h)",
        "kilowatt hour (kW.h)",
        "therm"    
    }; 
    
    // first convert it to joule (the base unit)
    private final static double[] JOULE_TABLE = {
        1.0,
        0.624146e+19,
        1e+7,
        0.73756,
        0.23885,
        0.10197,
        0.9478e-3,
        0.27778e-3,
        0.27778e-6,
        0.94781e-8    
    };
    
    /**
     * Get all the possible units.
     */
    public String[] getAllUnits() {
        return UNITS;
    }
    
    /**
     * Convert one unit from another
     */
    public String convertUnit(String value, int from, int to) throws UnitException {
        double inVal = getDoubleValue(value);
        double outVal = inVal*JOULE_TABLE[to]/JOULE_TABLE[from];
        return String.valueOf(outVal);
    }
    
    /**
     * Return unit type.
     */
    public String toString() {
        return "Energy";
    }
    
}